package cn.auto.utility;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSONObject;

/**
 * 
 * @author jli1 创建返回json对象
 */
public class ResponseInfo {

	@SuppressWarnings("unused")
	private static JSONObject buildResponseJson(HashMap<String, Object> headerHash, Object body) {
		JSONObject jo = new JSONObject();
		jo.put("headers", headerHash);
		jo.put("body", body);
		return jo;
	}
	
	private static HashMap<Object, Object> buildResponse(HashMap<String, Object> headerHash, Object body) {
		HashMap<Object, Object> jo = new HashMap<Object, Object>();
		jo.put("headers", headerHash);
		jo.put("body", body);
		return jo;
	}
	
	private static HashMap<Object, Object> buildResponseEui(String status,String msg,List<?> body) {
		HashMap<Object, Object> jo = new HashMap<Object, Object>();
		if(null==body){
			jo.put("status", status);
			jo.put("message", msg);
			jo.put("total", 0);
			jo.put("rows", new ArrayList());
		}else{
			jo.put("status", status);
			jo.put("message", msg);
			jo.put("total", body.size());
			jo.put("rows", body);
		}
		return jo;
	}

	private static HashMap<String, Object> header(String status, String msg) {
		HashMap<String, Object> header = new HashMap<String, Object>();
		header.put("status", status);
		header.put("message", msg);
		return header;
	}

	public static HashMap<Object, Object> create(String status, String msg, Object body) {
		HashMap<String, Object> header = new HashMap<>();
		header = header(status, msg);
		return buildResponse(header, body);
	}

	public static HashMap<Object, Object> create(String status, String msg) {
		HashMap<String, Object> header = new HashMap<>();
		header = header(status, msg);
		return buildResponse(header, new HashMap<String, Object>());
	}
	
	public static HashMap<Object, Object> createEui(String status,String msg,List<?> body) {
		return buildResponseEui(status,msg,body);
	}
}
